<template>
  <div class="lost-container">
    <el-card class="apply-card">
      <div class="title">
        <span class="desc">一卡通挂失</span>
        <img class="icon" src="@/assets/img/item-img/lost.png" alt="" />
      </div>
      <div class="body">
        <div class="info">
          <div class="reason-title">基本信息</div>
          <el-input class="disable-input" placeholder="姓名" disabled v-model="name">
            <template slot="prepend">姓名</template>
          </el-input>
          <el-input class="disable-input" placeholder="校号" disabled v-model="studentNum">
            <template slot="prepend">校号</template>
          </el-input>
          <el-input class="disable-input" placeholder="余额" disabled v-model="balance">
            <template slot="prepend">余额</template>
          </el-input>
        </div>
        <div class="reason-title">挂失原因</div>
        <el-input
          :autosize="{ minRows: 15 }"
          class="desc"
          type="textarea"
          :rows="15"
          placeholder="请输入挂失原因"
          v-model="reasonDesc"
        >
        </el-input>
        <div class="btn-container">
          <el-button type="primary" @click="commit">提交</el-button>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonServe from '../../api/service/common.serve'
export default {
  data() {
    return {
      id: window.sessionStorage.getItem('studentId'),
      name: '',
      studentNum: '',
      reasonDesc: '',
      balance: ''
    }
  },
  created() {
    this.getCardInfo()
  },
  methods: {
    //获取一卡通信息
    getCardInfo() {
      commonServe
        .getCardInfo(this.id)
        .then((res) => {
          console.log(res)
          if (res.code === 200) {
            let obj = res.data.card
            this.name = obj.studentName
            this.studentNum = obj.studentNum
            this.balance = obj.balance
          } else {
            this.$message.warning(res.message)
          }
        })
        .catch((err) => {
          this.$message.warning(err.message || '获取一卡通信息失败，请刷新重试')
        })
    },
    // 申请挂失
    commit() {
      if (!this.reasonDesc) {
        this.$message.info('挂失原因不能为空，请输入挂失原因')
        return
      } else {
        // console.log(this.reasonDesc)
        commonServe
          .lostCard(this.id, this.reasonDesc)
          .then((res) => {
            if (res.code === 200) {
              this.$message.success('挂失成功')
            } else {
              this.$message.warning('挂失失败，没有查询到卡信息')
            }
          })
          .catch((err) => {
            this.$message.warning('挂失失败')
          })
      }
    }
  }
}
</script>

<style lang="less" scoped>
.lost-container {
  .apply-card {
    .title {
      display: flex;
      align-items: center;
      .desc {
        font-size: 30px;
        color: #3a62d7;
        letter-spacing: 10px;
        font-weight: bold;
        text-shadow: 2px 2px 5px #999;
      }
      .icon {
        width: 40px;
        height: 40px;
      }
    }
    .body {
      padding: 50px 200px;
      .info {
        .disable-input {
          margin-bottom: 10px;
        }
        .el-input.is-disabled /deep/ .el-input__inner {
          color: #606266;
        }
      }
      .reason-title {
        padding-top: 20px;
        padding-bottom: 20px;
        font-size: 20px;
        color: #3a62d7;
      }
      .btn-container {
        padding: 100px 0 10px 0;
        .el-button {
          width: 100%;
          color: #fff;
        }
      }
    }
  }
}
</style>
